package kpi.java_training.domain.questions;

import kpi.java_training.domain.teaching.TeachingQuestionList;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by Alex Kebkalo (kebka@mail.ru) on 26.11.13.
 */
public class Topic {
    String topic;
    List<Question> questions;

    public Topic(String topic) {
        this.topic = topic;
        questions = new ArrayList<>();
    }

    public void add(Question question) {
        questions.add(question);
    }

    public Question getQuestion(int index) {
        return inRange(index) ? questions.get(index) : null;
    }

    public String getTopicName(){
        return topic;
    }

    public void shuffle() {
        Collections.shuffle(questions);
    }

    public TeachingQuestionList getTeachingList() {
        TeachingQuestionList list = new TeachingQuestionList();
        for (Question q : questions) {
            list.add(q);
        }
        return list;
    }

    private boolean inRange(int questionNumber) {
        return (questionNumber >= 0) && (questionNumber < questions.size());
    }

    public int size() {
        return questions.size();
    }
}
